package odgs.message.server;

import odgs.Connection;
import odgs.ExplorerNode;
import odgs.Result;
import odgs.message.Message;
import odgs.message.MessageHandler;
import odgs.message.MessageProcessor;
import odgs.transaction.RenameTransaction;

public class RenameTransactionRequestHandler implements MessageHandler
{
	public void execute(MessageProcessor processor, Message msg, Connection con)
	{
		RenameTransaction tran = (RenameTransaction) msg.get("transaction");
		ExplorerNode node = tran.getSource();
		String dest = tran.getDestName();
		Message reMsg = new Message(Message.RENAME_TRANSACTION_RESPONSE);
		reMsg.put("transaction", tran);
		
		int result = processor.getServerManager().rename(node, dest);
		
		if(result > 0)
		{
			reMsg.setResult(result);
			processor.getNetworkManager().broadcastMessage(reMsg);
		}
		else
		{
			reMsg.setResult(result);
			con.sendMessage(reMsg);
		}
	}
}